﻿using Nop.Core.Domain.Common;
using Nop.Core.Domain.Customers;
using System;
using System.Collections.Generic;

namespace Nop.Core.Domain.Orders
{
    public class Invoice : BaseEntity
    {
        #region Fields

        private ICollection<Order> _orders;

        private ICollection<InvoiceNote> _invoiceNotes;

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the invoice name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the customer identifier
        /// </summary>
        public int CustomerId { get; set; }

        /// <summary>
        /// Gets or sets the invoice identifier
        /// </summary>
        public Guid InvoiceGuid { get; set; }

        /// <summary>
        /// Gets or sets the invoice number
        /// </summary>
        public string InvoiceNumber { get; set; }

        /// <summary>
        /// Gets or sets the invoice status identifier
        /// </summary>
        public int InvoiceStatusId { get; set; }

        /// <summary>
        /// Gets or sets the comments for the invoice
        /// </summary>
        public string Comment { get; set; }

        /// <summary>
        /// Gets or sets the orders tax
        /// </summary>
        public decimal Tax { get; set; }

        /// <summary>
        /// Gets or sets the orders discount (applied to order total)
        /// </summary>
        public decimal Discount { get; set; }

        /// <summary>
        /// Gets or sets the percentage of order charge
        /// </summary>
        public decimal OrderChargePercentage { get; set; }

        /// <summary>
        /// Gets or sets the orders subtotal
        /// </summary>
        public decimal SubTotal { get; set; }

        /// <summary>
        /// Gets or sets the orders total
        /// </summary>
        public decimal Total { get; set; }

        /// <summary>
        /// Gets or sets the orders fuel surcharge
        /// </summary>
        public decimal? FuelSurcharge { get; set; }

        /// <summary>
        /// Gets or sets the creation time on UTC
        /// </summary>
        public DateTime CreatedOnUtc { get; set; }

        /// <summary>
        /// Gets or sets the due date of the invoice
        /// </summary>
        public DateTime? DueDate { get; set; }

        /// <summary>
        /// Gets or sets the paid date and time
        /// </summary>
        public DateTime? PaidDateUtc { get; set; }

        /// <summary>
        /// Gets or sets the district identifier
        /// </summary>
        public int DistrictId { get; set; }

        /// <summary>
        /// Gets or sets the store identifier for commerce orders
        /// </summary>
        public int? StoreId { get; set; }

        /// <summary>
        /// Gets or sets the monthly charge
        /// </summary>
        public decimal? MonthlyCharge { get; set; }

        /// <summary>
        /// Gets or sets the storage charge
        /// </summary>
        public decimal? StorageCharge { get; set; }

        /// <summary>
        /// Gets or sets the transaction processing charge charge
        /// </summary>
        public decimal? TransactionProcessingCharge { get; set; }

        /// <summary>
        /// Gets or sets the service charge
        /// </summary>
        public decimal? ServiceCharge { get; set; }

        /// <summary>
        /// Gets or sets the order kind identifier
        /// </summary>
        public int OrderKindId { get; set; }

        /// <summary>
        /// Gets or sets the time zone identifier
        /// </summary>
        public string TimeZoneId { get; set; }

        #endregion

        #region Navigation properties

        /// <summary>
        /// Gets or sets orders
        /// </summary>
        public virtual ICollection<Order> Orders
        {
            get { return _orders ?? (_orders = new List<Order>()); }
            set { _orders = value; }
        }

        public virtual ICollection<InvoiceNote> InvoiceNotes
        {
            get { return _invoiceNotes ?? (_invoiceNotes = new List<InvoiceNote>()); }
            set { _invoiceNotes = value; }
        }

        public virtual Customer Customer { get; set; }

        #endregion

        #region Customer properties

        /// <summary>
        /// Gets or sets the invoice status
        /// </summary>
        public virtual InvoiceStatus InvoiceStatus
        {
            get
            {
                return (InvoiceStatus)this.InvoiceStatusId;
            }
            set
            {
                this.InvoiceStatusId = (int)value;
            }
        }

        #endregion

    }
}
